﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace dllLink
{
    internal class Import
    {

        public Import(){ }

        public void ImportInitial(string[,] OPCVM1, string[,] OPCVM2, string[,] OPCVM3, string[,] OPCVM4, string[,] OPCVM5, string[,] OPCVM6, string[,] OPCVM7, string[,] OPCVM8, string[,] OPCVM9, string[,] OPCVM10, string[,] EURDOL, string[,] produitStruct,string[,] SR1, string[,] SR2, string[,] SR3, string[,] SR4, string[,] SR5, string[,] SR6)
        {
            moteurbd bd = new moteurbd();
            // Création de la base de donnée qui recevra les données historiques
            if (System.IO.File.Exists("ref.sdf"))
                System.IO.File.Delete("ref.sdf");
            if (!System.IO.File.Exists("ref.sdf"))
            {
                bd.CreateBase("Data Source = ref.sdf; Max Database Size = 4000;");
            }
            bd.Connect();

            Double past = -1;
            Double cur = 1;
            Double renta;
            String resu;
            String sCur;
            int length = OPCVM1.GetLength(0);

            for (int i = length -1; i >= 0; i--)   
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM1[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM1[i, 1]);
                    cur = Convert.ToDouble(OPCVM1[i, 1]);
                    resu = "";
                }


                // Appel à la fonction DateFromExcelToSQL pour convertir les dates format francais -> format US
                bd.insertOPCVM("OPCVM1", DateFromExcelToSQL(OPCVM1[i, 0]), OPCVM1[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM2.GetLength(0);
            for (int i = length - 1; i >= 0; i--)   
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM2[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM2[i, 1]);
                    cur = Convert.ToDouble(OPCVM2[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM2", DateFromExcelToSQL(OPCVM2[i, 0]), OPCVM2[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }
            
            past = -1;
            length = OPCVM3.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM3[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM3[i, 1]);
                    cur = Convert.ToDouble(OPCVM3[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM3", DateFromExcelToSQL(OPCVM3[i, 0]), OPCVM3[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM4.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM4[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM4[i, 1]);
                    cur = Convert.ToDouble(OPCVM4[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM4", DateFromExcelToSQL(OPCVM4[i, 0]), OPCVM4[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM5.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM5[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM5[i, 1]);
                    cur = Convert.ToDouble(OPCVM5[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM5", DateFromExcelToSQL(OPCVM5[i, 0]), OPCVM5[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM6.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM6[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM6[i, 1]);
                    cur = Convert.ToDouble(OPCVM6[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM6", DateFromExcelToSQL(OPCVM6[i, 0]), OPCVM6[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM7.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM7[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM7[i, 1]);
                    cur = Convert.ToDouble(OPCVM7[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM7", DateFromExcelToSQL(OPCVM7[i, 0]), OPCVM7[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM8.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM8[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM8[i, 1]);
                    cur = Convert.ToDouble(OPCVM8[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM8", DateFromExcelToSQL(OPCVM8[i, 0]), OPCVM8[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM9.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM9[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM9[i, 1]);
                    cur = Convert.ToDouble(OPCVM9[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM9", DateFromExcelToSQL(OPCVM9[i, 0]), OPCVM9[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }

            past = -1;
            length = OPCVM10.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(OPCVM10[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(OPCVM10[i, 1]);
                    cur = Convert.ToDouble(OPCVM10[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("OPCVM10", DateFromExcelToSQL(OPCVM10[i, 0]), OPCVM10[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
            }
            
            past = -1;
            length = SR1.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(SR1[i, 1])/100;
                    renta = cur - past;
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(SR1[i, 1])/100;
                    cur = Convert.ToDouble(SR1[i, 1])/100;
                    resu = "";
                }
                sCur = Convert.ToString(cur).Replace(',', '.');
                bd.insertOPCVM("SR1", DateFromExcelToSQL(SR1[i, 0]), sCur, resu.Replace(',', '.'));
            }

            past = -1;
            length = SR2.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(SR2[i, 1])/100;
                    renta = cur - past;
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(SR2[i, 1])/100;
                    cur = Convert.ToDouble(SR2[i, 1])/100;
                    resu = "";
                }
                sCur = Convert.ToString(cur).Replace(',', '.');
                bd.insertOPCVM("SR2", DateFromExcelToSQL(SR2[i, 0]), sCur, resu.Replace(',', '.'));
            }

            past = -1;
            length = SR3.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(SR3[i, 1])/100;
                    renta = cur - past;
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(SR3[i, 1])/100;
                    cur = Convert.ToDouble(SR3[i, 1])/100;
                    resu = "";
                }
                sCur = Convert.ToString(cur).Replace(',', '.');
                bd.insertOPCVM("SR3", DateFromExcelToSQL(SR3[i, 0]), sCur, resu.Replace(',', '.'));
            }

            past = -1;
            length = SR4.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(SR4[i, 1])/100;
                    renta = cur - past;
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(SR4[i, 1])/100;
                    cur = Convert.ToDouble(SR4[i, 1])/100;
                    resu = "";
                }
                sCur = Convert.ToString(cur).Replace(',', '.');
                bd.insertOPCVM("SR4", DateFromExcelToSQL(SR4[i, 0]), sCur, resu.Replace(',', '.'));
            }

            past = -1;
            length = SR5.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(SR5[i, 1])/100;
                    renta = cur - past;
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(SR5[i, 1])/100;
                    cur = Convert.ToDouble(SR5[i, 1])/100;
                    resu = "";
                }
                sCur = Convert.ToString(cur).Replace(',', '.');
                bd.insertOPCVM("SR5", DateFromExcelToSQL(SR5[i, 0]), sCur, resu.Replace(',', '.'));
            }

            past = -1;
            length = SR6.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(SR6[i, 1])/100;
                    renta = cur - past;
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(SR6[i, 1])/100;
                    cur = Convert.ToDouble(SR6[i, 1])/100;
                    resu = "";
                }
                sCur = Convert.ToString(cur).Replace(',', '.');
                bd.insertOPCVM("SR6", DateFromExcelToSQL(SR6[i, 0]), sCur, resu.Replace(',', '.'));
            }


            past = -1;
            length = produitStruct.GetLength(0);
            for (int i = length - 1; i >= 0; i--) 
            {
                bd.insertProduitCours("ProduitStruct", DateFromExcelToSQL(produitStruct[i, 0]), produitStruct[i, 1].Replace(',', '.'));
            }
            
            past = -1;
            length = EURDOL.GetLength(0);
            for (int i = 0; i < length; i++)
            {
                if (past > 0)
                {
                    past = cur;
                    cur = Convert.ToDouble(EURDOL[i, 1]);
                    renta = Math.Log(cur / past);
                    resu = renta.ToString();
                }
                else
                {
                    past = Convert.ToDouble(EURDOL[i, 1]);
                    cur = Convert.ToDouble(EURDOL[i, 1]);
                    resu = "";
                }
                bd.insertOPCVM("EURDOL", DateFromExcelToSQL(EURDOL[i, 0]), EURDOL[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                //bd.insertProduitCours("EURDOL", DateFromExcelToSQL(EURDOL[i, 0]), EURDOL[i, 1].Replace(',', '.'));
            }
            bd.Disconnect();
        }


        public string DateFromExcelToSQL(string date)
        {
            // Ceci est du au fait que les dates excel arrivent sous forme d'un int !!
            DateTime dt = new DateTime(1899, 12, 30).AddDays(Convert.ToDouble(date));
            String dispo_date = dt.ToShortDateString();

            string[] temp = dispo_date.Split('/');
            return temp[2]+temp[1]+temp[0];


        }

        public void Update(string[,] OPCVM1, string[,] OPCVM2, string[,] OPCVM3, string[,] OPCVM4, string[,] OPCVM5, string[,] OPCVM6, string[,] OPCVM7, string[,] OPCVM8, string[,] OPCVM9, string[,] OPCVM10, string[,] EURDOL, string[,] produitStruct, string[,] SR1, string[,] SR2, string[,] SR3, string[,] SR4, string[,] SR5, string[,] SR6)
        {
            moteurbd bd = new moteurbd();
            // Connection à la base de données.
            bd.Connect();

            Double past = -1;
            Double cur = 1;
            Double renta;
            String resu;
            int length = OPCVM1.GetLength(0);

            try
            {
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM1[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM1[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM1[i, 1]);
                        cur = Convert.ToDouble(OPCVM1[i, 1]);
                        resu = "";
                    }


                    // Appel à la fonction DateFromExcelToSQL pour convertir les dates format francais -> format US
                    bd.insertOPCVM("OPCVM1", DateFromExcelToSQL(OPCVM1[i, 0]), OPCVM1[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            {
            }

            try
            {
                past = -1;
                length = OPCVM2.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM2[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM2[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM2[i, 1]);
                        cur = Convert.ToDouble(OPCVM2[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM2", DateFromExcelToSQL(OPCVM2[i, 0]), OPCVM2[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
              }
            catch (Exception)
            {
            }

            try
            {
                past = -1;
                length = OPCVM3.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM3[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM3[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM3[i, 1]);
                        cur = Convert.ToDouble(OPCVM3[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM3", DateFromExcelToSQL(OPCVM3[i, 0]), OPCVM3[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            {
            }

            try
            {
                past = -1;
                length = OPCVM4.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM4[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM4[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM4[i, 1]);
                        cur = Convert.ToDouble(OPCVM4[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM4", DateFromExcelToSQL(OPCVM4[i, 0]), OPCVM4[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }

                past = -1;
                length = OPCVM5.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM5[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM5[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM5[i, 1]);
                        cur = Convert.ToDouble(OPCVM5[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM5", DateFromExcelToSQL(OPCVM5[i, 0]), OPCVM5[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }

            try
            {
                past = -1;
                length = OPCVM6.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM6[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM6[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM6[i, 1]);
                        cur = Convert.ToDouble(OPCVM6[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM6", DateFromExcelToSQL(OPCVM6[i, 0]), OPCVM6[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }

            try
            {
                past = -1;
                length = OPCVM7.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM7[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM7[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM7[i, 1]);
                        cur = Convert.ToDouble(OPCVM7[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM7", DateFromExcelToSQL(OPCVM7[i, 0]), OPCVM7[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }

            try
            {
                past = -1;
                length = OPCVM8.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM8[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM8[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM8[i, 1]);
                        cur = Convert.ToDouble(OPCVM8[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM8", DateFromExcelToSQL(OPCVM8[i, 0]), OPCVM8[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }

            try
            {
                past = -1;
                length = OPCVM9.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM9[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM9[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM9[i, 1]);
                        cur = Convert.ToDouble(OPCVM9[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM9", DateFromExcelToSQL(OPCVM9[i, 0]), OPCVM9[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }

            try
            {
                past = -1;
                length = OPCVM10.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (OPCVM10[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(OPCVM10[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(OPCVM10[i, 1]);
                        cur = Convert.ToDouble(OPCVM10[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("OPCVM10", DateFromExcelToSQL(OPCVM10[i, 0]), OPCVM10[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }
            String sCur;
            try
            {
                past = -1;
                length = SR1.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (SR1[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(SR1[i, 1]) / 100;
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(SR1[i, 1]) / 100;
                        cur = Convert.ToDouble(SR1[i, 1]) / 100;
                        resu = "";
                    }

                    sCur = Convert.ToString(cur).Replace(',', '.');
                    bd.insertOPCVM("SR1", DateFromExcelToSQL(SR1[i, 0]), sCur, resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }
            try
            {
                past = -1;
                length = SR2.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (SR2[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(SR2[i, 1]) / 100;
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(SR2[i, 1]) / 100;
                        cur = Convert.ToDouble(SR2[i, 1]) / 100;
                        resu = "";
                    }
                    sCur = Convert.ToString(cur).Replace(',', '.');
                    bd.insertOPCVM("SR2", DateFromExcelToSQL(SR2[i, 0]), sCur, resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            { }

            try
            {
                past = -1;
                length = SR3.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (SR3[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(SR3[i, 1]) / 100;
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(SR3[i, 1]) / 100;
                        cur = Convert.ToDouble(SR3[i, 1]) / 100;
                        resu = "";
                    }
                    sCur = Convert.ToString(cur).Replace(',', '.');
                    bd.insertOPCVM("SR3", DateFromExcelToSQL(SR3[i, 0]), sCur, resu.Replace(',', '.'));
                }
            }
            catch (Exception)
            {
            }
            

            try
            {
                past = -1;
                length = SR4.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (SR4[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(SR4[i, 1]) / 100;
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(SR4[i, 1]) / 100;
                        cur = Convert.ToDouble(SR4[i, 1]) / 100;
                        resu = "";
                    }
                    sCur = Convert.ToString(cur).Replace(',', '.');
                    bd.insertOPCVM("SR4", DateFromExcelToSQL(SR4[i, 0]), sCur, resu.Replace(',', '.'));
                }
            }
                        catch (Exception)
            {
            }

            try
            {
                past = -1;
                length = SR5.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (SR5[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(SR5[i, 1]) / 100;
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(SR5[i, 1]) / 100;
                        cur = Convert.ToDouble(SR5[i, 1]) / 100;
                        resu = "";
                    }
                    sCur = Convert.ToString(cur).Replace(',', '.');
                    bd.insertOPCVM("SR5", DateFromExcelToSQL(SR5[i, 0]), sCur, resu.Replace(',', '.'));
                }
            }
                        catch (Exception)
            {
            }

            try
            {
                past = -1;
                length = SR6.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (SR6[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(SR6[i, 1]) / 100;
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(SR6[i, 1]) / 100;
                        cur = Convert.ToDouble(SR6[i, 1]) / 100;
                        resu = "";
                    }
                    sCur = Convert.ToString(cur).Replace(',', '.');
                    bd.insertOPCVM("SR6", DateFromExcelToSQL(SR6[i, 0]), sCur, resu.Replace(',', '.'));
                }
            }
                        catch (Exception)
            {
            }

            try
            {
                past = -1;
                length = produitStruct.GetLength(0);
                for (int i = length - 1; i >= 0; i--)
                {
                    if (produitStruct[i, 1] == null)
                        continue;
                    bd.insertProduitCours("ProduitStruct", DateFromExcelToSQL(produitStruct[i, 0]), produitStruct[i, 1].Replace(',', '.'));
                }

                past = -1;
                length = EURDOL.GetLength(0);
                for (int i = 0; i < length; i++)
                {
                    if (EURDOL[i, 1] == null)
                        continue;
                    if (past > 0)
                    {
                        past = cur;
                        cur = Convert.ToDouble(EURDOL[i, 1]);
                        renta = Math.Log(cur / past);
                        resu = renta.ToString();
                    }
                    else
                    {
                        past = Convert.ToDouble(EURDOL[i, 1]);
                        cur = Convert.ToDouble(EURDOL[i, 1]);
                        resu = "";
                    }
                    bd.insertOPCVM("EURDOL", DateFromExcelToSQL(EURDOL[i, 0]), EURDOL[i, 1].Replace(',', '.'), resu.Replace(',', '.'));
                    //bd.insertProduitCours("EURDOL", DateFromExcelToSQL(EURDOL[i, 0]), EURDOL[i, 1].Replace(',', '.'));
                }
            }
            catch (Exception)
            {
            }
            bd.Disconnect();
        }

       
    }
}
